package l1j.server.server.clientpackets;

import java.util.logging.Level;
import java.util.logging.Logger;

import l1j.server.echo.ClientThread;
import l1j.server.server.model.L1CastleLocation;
import l1j.server.server.model.L1HouseLocation;
import l1j.server.server.model.Instance.L1PcInstance;
import l1j.server.server.serverpackets.S_ServerMessage;
import l1j.server.server.templates.L1BookMark;

/**
 * 要求增加記憶座標
 *
 */

public class C_AddBookmark extends ClientBasePacket {

	private static final String C_ADD_BOOKMARK = "[C] C_AddBookmark";
	private static final Logger _log = Logger.getLogger(C_AddBookmark.class.getName());

	@Override
	public String getType() {
		return C_ADD_BOOKMARK;
	}

	@Override
	public void start(final byte[] decrypt, final ClientThread client) {
		try {
			// 資料載入
			this.read(decrypt);

		final String s = this.readS();
		if(s == null){
			return;
		}
		final L1PcInstance pc = client.getActiveChar();
		if (pc.isGhost()) {
			return;
		}

		if (pc.getMap().isMarkable() || pc.isGm()) {
			if ((L1CastleLocation.checkInAllWarArea(pc.getX(), pc.getY(),pc.getMapId())
					|| L1CastleLocation.checkInAllfatArea(pc.getX(), pc.getY(),pc.getMapId())//opqlo 賭肥區判斷
					|| L1HouseLocation.isInHouse(pc.getX(),pc.getY(), pc.getMapId()))
					&& !pc.isGm()) {
				// \f1ここを記憶することができません。
				pc.sendPackets(new S_ServerMessage(214));
			} else {
				L1BookMark.addBookmark(pc, s);
			}
		} else {
			// \f1ここを記憶することができません。
			pc.sendPackets(new S_ServerMessage(214));
		}
		} catch (final Exception e) {
			_log.log(Level.SEVERE, e.getLocalizedMessage(), e);

		} finally {
			this.over();
		}
	}
}
